package com.baizhi.service.impl;

import com.baizhi.dao.GuruDAO;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class GuruServiceImpl implements GuruService {
    @Autowired
    private GuruDAO guruDAO;
    @Override
    public PageInfo<Guru> selectAll(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Guru> list = guruDAO.selectAll();
        PageInfo<Guru> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void updateStatus(Guru record) {
        if(record.getGuruStatus()==0){
            record.setGuruStatus(1);
        }else {
            record.setGuruStatus(0);
        }
        guruDAO.updateStatus(record);
    }

    @Override
    public void insert(Guru record) {
        guruDAO.insert(record);
    }

    @Override
    public void deleteByPrimaryKey(Integer guruId) {
        guruDAO.deleteByPrimaryKey(guruId);
    }
}
